<?php
/**
 * @category     APPCore
 * @package     APPCore >> Base model
 * @copyright     Copyright(c) 2000-2013
 * @license     http://www.yourdomain.com
 * @version     APPCore version 1.0.0
 * @author         
 * @implement     Name of developer
 */


class Model_Entities_Content
{

    /**
     * @var Model_Entities_Mapper_ContentMapper
     */
    protected $_mapper = null;

    /**
     * @var int
     */
    protected $_id = null;

    /**
     * @var varchar
     */
    protected $_name = null;

    /**
     * @var tinytext
     */
    protected $_introtext = null;

    /**
     * @var longtext
     */
    protected $_fulltext = null;

    /**
     * @var text
     */
    protected $_images = null;

    /**
     * @var text
     */
    protected $_files = null;

    /**
     * @var int
     */
    protected $_sectionId = null;

    /**
     * @var int
     */
    protected $_categoryId = null;

    /**
     * @var int
     */
    protected $_published = null;

    /**
     * @var int
     */
    protected $_userId = null;

    /**
     * @var timestamp
     */
    protected $_createdDate = null;

    /**
     * @var timestamp
     */
    protected $_modifiedDate = null;

    /**
     * Constructor
     * 
     * @param array|null $options
     * @return void
     */
    public function __construct(Array $options = array())
    {
        if (is_array($options) && count($options) > 0) {
            $this->setOptions($options);
        }
    }

    /**
     * Overloading: allow property access
     * 
     * @param mixed $value
     * @param string|null $name
     * @return void
     */
    public function __set($name = null, $value = null)
    {
        $method = 'set' . $name;
        if ('mapper' == $name || ! method_exists($this, $method)) {
            throw Zend_Exception('Invalid property specified');
        }
        $this->$method($value);
    }

    /**
     * Overloading: allow property access
     * 
     * @param string|null $name
     * @return mixed
     */
    public function __get($name = null)
    {
        $method = 'get' . $name;
        if ('mapper' == $name || ! method_exists($this, $method)) {
            throw Zend_Exception('Invalid property specified');
        }
        return $this->$method();
    }

    /**
     * Set data mapper
     * 
     * @param mixed $mapper
     * @return mixed
     */
    public function setMapper($mapper = null)
    {
        $this->_mapper = $mapper;
        return $this;
    }

    /**
     * Get data mapper
     * 
     * @return mixed
     */
    public function getMapper()
    {
        if (null === $this->_mapper) {
            $this->setMapper(new Model_Entities_Mapper_ContentMapper());
        }
        return $this->_mapper;
    }

    /**
     * Set object state
     * 
     * @param array $options
     * @return mixed
     */
    public function setOptions(Array $options = null)
    {
        $methods = get_class_methods($this);
        foreach ($options as $key => $value) {
            $key = explode('_', $key);
            foreach ($key as $k => $v) {
                $key[$k] = ucfirst($v);
            }
            $key = implode('', $key);
            $method = 'set' . ucfirst($key);
            if (in_array($method, $methods)) {
                $this->$method($value);
            }
        }
        return $this;
    }

    /**
     * Set the _id property
     * 
     * @param int $value
     * @return mixed
     */
    public function setId($value = null)
    {
        $this->_id = $value;
        return $this;
    }

    /**
     * Retrieve the _id property
     * 
     * @return int|null
     */
    public function getId()
    {
        return $this->_id;
    }

    /**
     * Set the _name property
     * 
     * @param string $value
     * @return mixed
     */
    public function setName($value = null)
    {
        $this->_name = $value;
        return $this;
    }

    /**
     * Retrieve the _name property
     * 
     * @return string|null
     */
    public function getName()
    {
        return $this->_name;
    }

    /**
     * Set the _introtext property
     * 
     * @param string $value
     * @return mixed
     */
    public function setIntrotext($value = null)
    {
        $this->_introtext = $value;
        return $this;
    }

    /**
     * Retrieve the _introtext property
     * 
     * @return string|null
     */
    public function getIntrotext()
    {
        return $this->_introtext;
    }

    /**
     * Set the _fulltext property
     * 
     * @param string $value
     * @return mixed
     */
    public function setFulltext($value = null)
    {
        $this->_fulltext = $value;
        return $this;
    }

    /**
     * Retrieve the _fulltext property
     * 
     * @return string|null
     */
    public function getFulltext()
    {
        return $this->_fulltext;
    }

    /**
     * Set the _images property
     * 
     * @param string $value
     * @return mixed
     */
    public function setImages($value = null)
    {
        $this->_images = $value;
        return $this;
    }

    /**
     * Retrieve the _images property
     * 
     * @return string|null
     */
    public function getImages()
    {
        return $this->_images;
    }

    /**
     * Set the _files property
     * 
     * @param string $value
     * @return mixed
     */
    public function setFiles($value = null)
    {
        $this->_files = $value;
        return $this;
    }

    /**
     * Retrieve the _files property
     * 
     * @return string|null
     */
    public function getFiles()
    {
        return $this->_files;
    }

    /**
     * Set the _sectionId property
     * 
     * @param int $value
     * @return mixed
     */
    public function setSectionId($value = null)
    {
        $this->_sectionId = $value;
        return $this;
    }

    /**
     * Retrieve the _sectionId property
     * 
     * @return int|null
     */
    public function getSectionId()
    {
        return $this->_sectionId;
    }

    /**
     * Set the _categoryId property
     * 
     * @param int $value
     * @return mixed
     */
    public function setCategoryId($value = null)
    {
        $this->_categoryId = $value;
        return $this;
    }

    /**
     * Retrieve the _categoryId property
     * 
     * @return int|null
     */
    public function getCategoryId()
    {
        return $this->_categoryId;
    }

    /**
     * Set the _published property
     * 
     * @param int $value
     * @return mixed
     */
    public function setPublished($value = null)
    {
        $this->_published = $value;
        return $this;
    }

    /**
     * Retrieve the _published property
     * 
     * @return int|null
     */
    public function getPublished()
    {
        return $this->_published;
    }

    /**
     * Set the _userId property
     * 
     * @param int $value
     * @return mixed
     */
    public function setUserId($value = null)
    {
        $this->_userId = $value;
        return $this;
    }

    /**
     * Retrieve the _userId property
     * 
     * @return int|null
     */
    public function getUserId()
    {
        return $this->_userId;
    }

    /**
     * Set the _createdDate property
     * 
     * @param string $value
     * @return mixed
     */
    public function setCreatedDate($value = null)
    {
        $this->_createdDate = $value;
        return $this;
    }

    /**
     * Retrieve the _createdDate property
     * 
     * @return string|null
     */
    public function getCreatedDate()
    {
        return $this->_createdDate;
    }

    /**
     * Set the _modifiedDate property
     * 
     * @param string $value
     * @return mixed
     */
    public function setModifiedDate($value = null)
    {
        $this->_modifiedDate = $value;
        return $this;
    }

    /**
     * Retrieve the _modifiedDate property
     * 
     * @return string|null
     */
    public function getModifiedDate()
    {
        return $this->_modifiedDate;
    }

    /**
     * Save the current entry
     * 
     * @param array $filterArray
     * @return mixed
     */
    public function save(Array $filterArray = array())
    {
        return $this->getMapper()->save($this, $filterArray, true, 'id');
    }

    /**
     * Move the current entry
     * 
     * @param int $dirn
     * @param array $filterArray
     * @return mixed
     */
    public function move($dirn, Array $filterArray = array())
    {
        return $this->getMapper()->move($this, $dirn, $filterArray);
    }

    /**
     * Save the current entry
     * 
     * @param array $filterArray
     * @return mixed
     */
    public function reorder(Array $filterArray = array())
    {
        return $this->getMapper()->move($this, $filterArray);
    }

    /**
     * Find an entry
     * 
     * Resets entry state if matching id found.
     * 
     * @param int $id
     * @return mixed
     */
    public function find($id)
    {
        $this->getMapper()->find($id, $this);
        return $this;
    }

    /**
     * Find an entry
     * 
     * Resets entry state if matching id found.
     * 
     * @param int $id
     * @return mixed
     */
    public function search($columnName, $keyword)
    {
        return $this->getMapper()->search($columnName, $keyword);
    }

    /**
     * Delete an entry
     * 
     * Resets entry state if matching id found.
     * 
     * @param Array $ids
     * @return mixed
     */
    public function delete(Array $ids = array())
    {
        return $this->getMapper()->delete($ids);
    }

    /**
     * Retrieve array data
     * 
     * Get all data from single table
     * 
     * @return array
     */
    public function toArray()
    {
        return $this->getMapper()->toArray($this);
    }

    /**
     * Retrieve array data
     * 
     * Get all data from single table
     * 
     * @param int $page
     * @param int $limit
     * @param Array $wheres
     * @param Array $orders
     * @return array
     */
    public function getArray($page, $limit, Array $wheres = array(), Array $orders = array())
    {
        return $this->getMapper()->getArray($page, $limit, $wheres, $orders);
    }

    /**
     * Retrieve array data
     * 
     * Get all data from single table
     * 
     * @param int $page
     * @param int $limit
     * @param Array $wheres
     * @param Array $orders
     * @return Object
     */
    public function getObject($page, $limit, Array $wheres = array(), Array $orders = array())
    {
        return $this->getMapper()->getObject($page, $limit, $wheres, $orders);
    }

    /**
     * Get total entries
     * 
     * Resets entry state if matching id found.
     * 
     * @param Array $wheres
     * @return mixed
     */
    public function getTotalEntries(Array $wheres = array())
    {
        return $this->getMapper()->getTotalEntries($wheres);
    }

    /**
     * Retrieve string data
     * 
     * Get table prefix
     */
    public function getTablePrefix()
    {
        return 'bb_';
    }


}

